﻿
@using YouWei.Infrastructure.Entity;
@model YouWei.Infrastructure.Models.GroupCommentDto

@{var commentlist = ViewBag.GroupCommentImages as List<GroupCommentImage> ?? new List<GroupCommentImage>();}
@{
    ViewBag.Title = "群空间内容详情";
    Layout = "~/Views/Shared/_Layout.cshtml";
}

<section class="content-header">
    <h1>
        群空间内容管理
        <small></small>
    </h1>
    <ol class="breadcrumb">
        <li><a href="#"><i class="fa fa-dashboard"></i>主页</a></li>
        <li class="active">群空间内容详情</li>
    </ol>
</section>
<section class="content">
    <div class="row">
        <div class="col-md-12">
            <div class="box box-primary">
                <div class="box-header">
                    <table class="table table-striped">
                        <tr>
                            <td>名称</td>
                            <td>@Model.CommentName</td>
                            <td>
                                @if (Model.IsHot == 0)
                                {
                                    <input type="button" class="btn btn-primary" onclick="setHot(1)" value="设置热门" />
                                }
                                @if (Model.IsHot == 1)
                                {
                                    <input type="button" class="btn btn-primary" onclick="setHot(0)" value="取消热门" />
                                }
                            </td>
                        </tr>
                        <tr>
                            <td>所属模块</td>
                            @if (Model.CommentSection == 1)
                            {
                                <td>随笔</td>
                            }
                            else if (Model.CommentSection == 2)
                            {
                                <td>游记</td>
                            }
                            else if (Model.CommentSection == 3)
                            {
                                <td>求助</td>
                            }
                            else if (Model.CommentSection == 4)
                            {
                                <td>心情</td>
                            }
                            else
                            {
                                <td>心情</td>
                            }
                            <td>用户名称</td>
                            <td>@ViewBag.UserName</td>
                        </tr>
                        <tr>
                            <td>是否可见</td>
                            @if (@Model.IsShow == 1)
                            {
                                <td>是</td>
                            }
                            @if (@Model.IsShow == 0)
                            {
                                <td>否</td>
                            }
                            <td>来源内容ID</td>
                            <td>@Model.SourceID</td>
                        </tr>
                        <tr>
                            <td>创建时间</td>
                            <td>@Model.CreateDate.ToString("yyyy-MM-dd HH:mm")</td>
                            <td>更新时间</td>
                            <td>@Model.UpdateDate.ToString("yyyy-MM-dd HH:mm")</td>
                        </tr>
                        <tr>
                            <td>简图</td>
                            <td>
                                <table>
                                    <tr>
                                        @foreach (var item in commentlist)
                                        {
                                            <td><img class="" style="width:100px;height:100px;" src="@item.ImageUrl" /> </td>
                                        }
                                    </tr>
                                </table>
                            </td>
                        </tr>
                        <tr>
                            <td>简介</td>
                            <td colspan="3">@Model.CommentDesc</td>
                        </tr>
                        <tr>
                            <td>详情</td>
                            <td colspan="3" rowspan="3">@Html.Raw(Model.Detail) </td>
                        </tr>
                    </table>
                </div>
                <div class="box-body table-responsive no-padding">
                    <div class="box box-primary">
                        <div class="box-header">
                            <div class="h4">评论列表</div>
                        </div>
                        <div class="box-body table-responsive no-padding">
                            <table class="table table-bordered table-hover body-table-head">
                                <thead>
                                    <tr>
                                        <th>
                                            ID
                                        </th>
                                        <th>
                                            评论内容
                                        </th>
                                        <th>
                                            创建时间
                                        </th>
                                        <th class="t_c">
                                            操作
                                        </th>
                                    </tr>
                                </thead>
                                <tbody id="tbodylist"></tbody>
                            </table>
                            <div class="no-data" id="nodata" style="display:none;">
                                <div class="img-box"></div>
                                <div class="text">暂无数据</div>
                            </div>
                        </div>
                        <div class="box-footer clearfix" style="text-align:center;vertical-align:middle;">
                            <a class="btn btn-danger" href="@Url.Action("GroupCommentIndex","GroupComment")">返回</a>
                        </div>
                        <!-- /.box-body -->
                        <!-- /.box -->
                    </div>
                </div>
            </div>
        </div>
</section>
@section scriptsBottom{
    <script src="@Url.Content("~/lib/art-template/template-web.js")"></script>
    <script id="dataItemTpl" type="text/html">
        {{each rows}}
        <tr>
            <td class="title">
                {{$value.TrailCommentID}}
            </td>
            <td class="title">
                {{$value.Comment}}
            </td>
            <td>
                {{$value.CreateDate}}
            </td>
            <td class="t_c">
                {{if $value.IsShow!=1}}
                <button type="button" class="btn btn-info btn-xs" onclick="setTraIsShow({{$value.TrailCommentID}},1)">审核通过</button>
                {{/if}}
            </td>
        </tr>
        {{/each}}
    </script>
    <script type="text/javascript">
        $(document).ready(function () {
            //分类
            childList();
        });

        //页码
        var pageIndex = 1;
        //查询
        function childList() {
            var url = '@Url.Action("TrailList", "GroupComment")' + "?page=" + pageIndex +"&groupCommentId="+@Model.GroupCommentID;
            //查询列表
            BMCW.ajax({
                url: url,
                type: 'GET',
                dataType: "json",
                success: function (dt) {
                    if (dt.total < 1) {
                        $("#nodata").show();
                        document.getElementById('tbodylist').innerHTML = "";
                        return;
                    }
                    $("#nodata").hide();
                    //模板渲染
                    var data = dt.rows;
                    var html = template('dataItemTpl', dt);
                    document.getElementById('tbodylist').innerHTML = html;
                    //分页显示
                    $('#pagination').twbsPagination("destroy");
                    $('#pagination').twbsPagination({
                        totalItems: dt.total,
                        visiblePages: 10,
                        pageSize: 10,
                        startPage: parseInt(pageIndex),
                        onPageClick: function (event, page) {
                            pageIndex = page;
                            childList();
                        }
                    });
                }
            });
        }

         //用户详情
        function detail(userid) {
            var url = '@Url.Action("Detail", "User")' + "?userId=" + userid;
            location.href = url;
        }
        //设置热门
        function setHot(isHot) {
                var id = "@Model.GroupCommentID";
                BMCW.ajax({
                    url: "@Url.Action("UpdateCommentIsHot", "GroupComment")?id=" + id + "&isHot=" + isHot,
                        type:"POST",
                        success: function (data) {
                            if (data.status == 0) {
                                BMCW.alert("更新状态成功");
                                setTimeout(function () {
                                    window.location.reload();
                                }, 2000);
                            } else {
                                BMCW.alert(data.message);
                            }
                        }
                    });
        }

        //留言审核
        function setTraIsShow(id, isShow) {
            var data = {
                "TrailCommentID": id,
                "IsShow": isShow
            };
                BMCW.ajax({
                    url: "@Url.Action("SetTrailCommentIsShow", "GroupComment")",
                    type: "POST",
                        data:data,
                        success: function (data) {
                            if (data.status == 0) {
                                BMCW.alert("审核成功");
                                setTimeout(function () {
                                    window.location.reload();
                                }, 2000);
                            } else {
                                BMCW.alert(data.message);
                            }
                        }
                    });
            }
    </script>
}